package com.pwser.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.pwser.entities.Menu;
import com.pwser.entities.Role;
import com.pwser.entities.User;

@Mapper
public interface LoginMapper {
	
	//查询所有用户
	@Select("select * from t_user u")
	public List<User> findAllUsers();
	
	//根据用户id修密码
	@Update("update t_user u set u.login_pass=#{user.loginPass} where u.user_id=#{user.userId}")
	public void updateUserPassword(@Param("user") User user);
	
	//根据账号查询用户
	@Select("select * from t_user where login_account = #{account}")
	public User findUserByAccount(String account);
	
	//根据账号查询用户的角色
	@Select("select r.* from t_user_role ur "
			+ "left join t_role r on ur.role_id=r.role_id "
			+ "left join t_user u on ur.user_id=u.user_id "
			+ "where u.login_account = #{account}")
	public List<Role> findRolesByAccount(String account);
	
	//查询所有菜单
	@Select("select m.*, r.role_no from t_menu m "
			+ "inner join t_role_menu rm on rm.menu_id = m.menu_id "
			+ "inner join t_role r on r.role_id = rm.role_id")
	public List<Menu> findAllMenus();

}
